home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 January: Mac OS SDK / Dev.CD Jan 96 SDK / Dev.CD Jan 96 SDK2.toast / Development Kits (Disc 2) / QuickDraw™ 3D / Development / QAL DDK 1.0.3 / Headers / Drive3D.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-09  |  32.3 KB  |  848 lines  |  [TEXT/MPS ]

  1. /******************************************************************************
  2.  **                                                                             **
  3.  **     Module:        Drive3D.h                                                 **
  4.  **                                                                          **
  5.  **     Purpose:     Header file for low-level 3D driver API                     **
  6.  **                                                                          **
  7.  **     Author:        Mike W. Kelley                                             **
  8.  **                                                                          **
  9.  **     Copyright (C) 1994-95 Apple Computer, Inc.  All rights reserved.     **
  10.  **        OpenGL™ is a trademark of Silicon Graphics, Inc.                     **
  11.  **                                                                          **
  12.  *****************************************************************************/
  13.  
  14. #ifndef _Drive3D_h
  15. #define _Drive3D_h
  16.  
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20.  
  21. /************************************************************************************************
  22.  *
  23.  * Platform macros. This sets kQAPlatform to one of kQAMacOS or kQAGeneric. kQAPlatform
  24.  * controls platform-specific compilation switches.
  25.  *
  26.  ***********************************************************************************************/
  27.  
  28. #if !defined(kQAMacOS) || !defined(kQAGeneric) || !defined(kQAPlatform)
  29.     Error: kQAPlatform, kQAMacOS, and kQAGeneric must be defined. For example:
  30.     
  31.     #define    kQAMacOS    1            /* Target is MacOS                    */
  32.     #define kQAGeneric    2            /* Target is generic platform        */
  33.     #define kQAPlatform    kQAMacOS    /* Compile for MacOS */
  34. #endif
  35.  
  36. /************************************************************************************************
  37.  *
  38.  * Platform dependent datatypes: TQAImagePixelType, TQADevice, TQAClip, and TQARect.
  39.  *
  40.  ***********************************************************************************************/
  41.  
  42. typedef enum TQAImagePixelType
  43. {
  44.     kQAPixel_Alpha1        = 0,        /* 1 bit/pixel alpha */
  45.     kQAPixel_RGB16        = 1,        /* 16 bit/pixel, R=14:10, G=9:5, B=4:0 */
  46.     kQAPixel_ARGB16        = 2,        /* 16 bit/pixel, A=15, R=14:10, G=9:5, B=4:0 */
  47.     kQAPixel_RGB32        = 3,        /* 32 bit/pixel, R=23:16, G=15:8, B=7:0 */
  48.     kQAPixel_ARGB32        = 4            /* 32 bit/pixel, A=31:24, R=23:16, G=15:8, B=7:0 */
  49. } TQAImagePixelType;
  50.  
  51. typedef enum TQADeviceType            /* Selects target device type */
  52. {
  53.     kQADeviceMemory        = 0,        /* Memory draw context */
  54.     kQADeviceGDevice    = 1,        /* Macintosh GDevice draw context */
  55.     kQADeviceWindows    = 2            /* Windows xxx draw context */
  56. } TQADeviceType;
  57.  
  58. typedef struct TQADeviceMemory        /* Generic memory pixmap device */
  59. {
  60.     long                rowBytes;    /* Rowbytes */
  61.     TQAImagePixelType    pixelType;    /* Depth, color space, etc. */
  62.     long                width;        /* Width in pixels */
  63.     long                height;        /* Height in pixels */
  64.     void                *baseAddr;    /* Base address of pixmap */
  65. } TQADeviceMemory;
  66.  
  67. typedef enum TQAClipType            /* Selects target clip type */
  68. {
  69.     kQAClipRgn            = 0            /* Macintosh clipRgn with serial number */
  70. } TQAClipType;
  71.  
  72. typedef struct TQARect
  73. {
  74.     long                left;
  75.     long                right;
  76.     long                top;
  77.     long                bottom;
  78. } TQARect;
  79.  
  80. #if !defined(kQAPlatform) || !defined(kQAMacOS) || !defined(kQAGeneric)
  81.     ??? Error: The above defines must be set before compilation
  82. #endif
  83.  
  84. #if (kQAPlatform == kQAMacOS)
  85.     /*
  86.      * MacOS supports memory and GDevice. TQARect == Rect. TQAClip is a clipRgn.
  87.      */
  88.     
  89.     #include <Quickdraw.h>
  90.     #include <QDOffscreen.h>
  91.     
  92.     typedef union TQAPlatformDevice
  93.     {
  94.         TQADeviceMemory    memoryDevice;
  95.         GDHandle        gDevice;
  96.     } TQAPlatformDevice;
  97.     
  98.     typedef union TQAPlatformClip
  99.     {
  100.         RgnHandle        clipRgn;
  101.     } TQAPlatformClip;
  102.     
  103. #elif (kQAPlatform == kQAGeneric)
  104.     /*
  105.      * Generic platform supports memory device only. TQARect is generic. TQAClip is ???.
  106.      */
  107.     
  108.     typedef union TQAPlatformDevice
  109.     {
  110.         TQADeviceMemory    memoryDevice;
  111.     } TQAPlatformDevice;
  112.     
  113.     typedef union TQAPlatformClip
  114.     {
  115.         void            *region;        /* ??? */
  116.     } TQAPlatformClip;
  117. #else
  118.     ??? Unrecognized kQAPlatform
  119. #endif
  120.  
  121. typedef struct TQADevice
  122. {
  123.     TQADeviceType        deviceType;
  124.     TQAPlatformDevice    device;
  125. } TQADevice;
  126.  
  127. typedef struct TQAClip
  128. {
  129.     TQAClipType            clipType;
  130.     TQAPlatformClip        clip;
  131. } TQAClip;
  132.  
  133. /************************************************************************************************
  134.  *
  135.  * Basic data types.
  136.  *
  137.  ***********************************************************************************************/
  138.  
  139. typedef struct    TQADrawContext TQADrawContext;    /* Drawing context for an engine */
  140. typedef struct    TQAEngine TQAEngine;            /* Pointer to a drawing engine */
  141. typedef struct    TQATexture TQATexture;            /* Pointer to an allocated texture map */
  142. typedef struct    TQABitmap TQABitmap;            /* Pointer to an allocated bitmap */
  143. typedef struct    TQADrawPrivate TQADrawPrivate;    /* Engine's private draw context pointer */
  144. typedef struct    TQAImage TQAImage;                /* An image for use as texture or bitmap */
  145.  
  146. struct TQAImage
  147. {
  148.     long        width;                            /* Width of pixmap */
  149.     long        height;                            /* Height of pixmap */
  150.     long        rowBytes;                        /* Rowbytes of pixmap */
  151.     void        *pixmap;                        /* Pixmap */
  152. };
  153.  
  154. typedef enum TQAError
  155. {
  156.     kQANoErr                = 0,                /* No error */
  157.     kQAError                = 1,                /* Generic error flag */
  158.     kQAOutOfMemory            = 2,                /* Insufficient memory */
  159.     kQANotSupported            = 3,                /* Requested feature is not supported */
  160.     kQAOutOfDate            = 4,                /* A newer drawing engine was registered */
  161.     kQAParamErr                = 5,                /* Error in passed parameters */
  162.     kQAGestaltUnknown        = 6                    /* Requested gestalt type isn't available */
  163. } TQAError;
  164.  
  165. /************************************************************************************************
  166.  *
  167.  * Vertex data types.
  168.  *
  169.  ***********************************************************************************************/
  170.  
  171. /*
  172.  * TQAVGouraud is used for Gouraud shading. Each vertex specifies position, color and Z.
  173.  *
  174.  * Alpha is always treated as indicating transparency. Drawing engines which don't
  175.  * support Z-sorted rendering use the back-to-front transparency blending functions
  176.  * shown below. (ARGBsrc are the source (new) values, ARGBdest are  the destination
  177.  * (previous) pixel values.)
  178.  *
  179.  *        Premultiplied                            Interpolated
  180.  *
  181.  *        A = 1 - (1 - Asrc) * (1 - Adest)        A = 1 - (1 - Asrc) * (1 - Adest) 
  182.  *        R = (1 - Asrc) * Rdest + Rsrc            R = (1 - Asrc) * Rdest + Asrc * Rsrc
  183.  *        G = (1 - Asrc) * Gdest + Gsrc            G = (1 - Asrc) * Gdest + Asrc * Gsrc
  184.  *        B = (1 - Asrc) * Bdest + Bsrc            B = (1 - Asrc) * Bdest + Asrc * Bsrc
  185.  *
  186.  * Note that the use of other blending modes to implement antialiasing is performed
  187.  * automatically by the drawing engine when the kQATag_Antialias variable !=
  188.  * kQAAntiAlias_Fast. The driving software should continue to use the alpha fields
  189.  * for transparency even when antialiasing is being used (the drawing engine will
  190.  * resolve the multiple blending requirements as best as it can).
  191.  *
  192.  * Drawing engines which perform front-to-back Z-sorted rendering should replace
  193.  * the blending function shown above with the equivalent front-to-back formula.
  194.  */
  195.  
  196. typedef struct TQAVGouraud
  197. {
  198.     float                x;        /* X pixel coordinate, 0.0 <= x < width */
  199.     float                y;        /* Y pixel coordinate, 0.0 <= y < height */
  200.     float                z;        /* Z coordinate, 0.0 <= z <= 1.0 */
  201.     float                invW;    /* 1 / w; required only when kQAPerspectiveZ_On is set */
  202.     
  203.     float                r;        /* Red, 0.0 <= r <= 1.0 */
  204.     float                g;        /* Green, 0.0 <= g <= 1.0 */
  205.     float                b;        /* Blue, 0.0 <= b <= 1.0 */
  206.     float                a;        /* Alpha, 0.0 <= a <= 1.0, 1.0 is opaque */
  207. } TQAVGouraud;
  208.  
  209. /*
  210.  * TQAVTexture is used for texture mapping. The texture mapping operation
  211.  * is controlled by the kQATag_TextureOp variable, which is a mask of
  212.  * kQATextureOp_None/Modulate/Highlight/Decal. Below is pseudo-code for the
  213.  * texture shading operation:
  214.  *
  215.  *        texPix = TextureLookup (uq/q, vq/q);
  216.  *        if (kQATextureOp_Decal)
  217.  *        {
  218.  *            texPix.r = texPix.a * texPix.r + (1 - texPix.a) * r;
  219.  *            texPix.g = texPix.a * texPix.g + (1 - texPix.a) * g;
  220.  *            texPix.b = texPix.a * texPix.b + (1 - texPix.a) * b;
  221.  *            texPix.a = a;
  222.  *        }
  223.  *        else
  224.  *        {
  225.  *            texPix.a = texPix.a * a;
  226.  *        }
  227.  *        if (kQATextureOp_Modulate)
  228.  *        {
  229.  *            texPix.r *= kd_r;        // Clamped to prevent overflow
  230.  *            texPix.g *= kd_g;        // Clamped to prevent overflow
  231.  *            texPix.b *= kd_b;        // Clamped to prevent overflow
  232.  *        }
  233.  *        if (kQATextureOp_Highlight)
  234.  *        {
  235.  *            texPix.r += ks_r;        // Clamped to prevent overflow
  236.  *            texPix.g += ks_g;        // Clamped to prevent overflow
  237.  *            texPix.b += ks_b;        // Clamped to prevent overflow
  238.  *        }
  239.  *
  240.  * After computation of texPix, transparency blending (as shown
  241.  * above for TQAVGouraud) is performed.
  242.  */
  243.  
  244. typedef struct TQAVTexture
  245. {
  246.     float                x;        /* X pixel coordinate, 0.0 <= x < width */
  247.     float                y;        /* Y pixel coordinate, 0.0 <= y < height */
  248.     float                z;        /* Z coordinate, 0.0 <= z <= 1.0 */
  249.     float                invW;    /* 1 / w (always required) */
  250.     
  251.     /* rgb are used only when kQATextureOp_Decal is set. a is always required */
  252.     
  253.     float                r;        /* Red, 0.0 <= r <= 1.0 */
  254.     float                g;        /* Green, 0.0 <= g <= 1.0 */
  255.     float                b;        /* Blue, 0.0 <= b <= 1.0 */
  256.     float                a;        /* Alpha, 0.0 <= a <= 1.0, 1.0 is opaque */
  257.  
  258.     /* uOverW and vOverW are required by all modes */
  259.     
  260.     float                uOverW;    /* u / w */
  261.     float                vOverW;    /* v / w */
  262.     
  263.     /* kd_r/g/b are used only when kQATextureOp_Modulate is set */
  264.     
  265.     float                kd_r;    /* Scale factor for texture red, 0.0 <= kd_r */
  266.     float                kd_g;    /* Scale factor for texture green, 0.0 <= kd_g */
  267.     float                kd_b;    /* Scale factor for texture blue, 0.0 <= kd_b */
  268.     
  269.     /* ks_r/g/b are used only when kQATextureOp_Highlight is set */
  270.     
  271.     float                ks_r;    /* Red specular highlight, 0.0 <= ks_r <= 1.0 */
  272.     float                ks_g;    /* Green specular highlight, 0.0 <= ks_g <= 1.0 */
  273.     float                ks_b;    /* Blue specular highlight, 0.0 <= ks_b <= 1.0 */
  274. } TQAVTexture;
  275.  
  276. /************************************************************************************************
  277.  *
  278.  * Constants used for the state variables.
  279.  *
  280.  ***********************************************************************************************/
  281.  
  282. /*
  283.  * kQATag_xxx is used to select a state variable when calling QASetFloat(), QASetInt(),
  284.  * QAGetFloat() and QAGetInt(). The kQATag values are split into two separate
  285.  * enumerated types: TQATagInt and TQATagFloat. TQATagInt is used for the QASet/GetInt()
  286.  * functions, and TQATagFloat is used for the QASet/GetFloat() functions. (This is so
  287.  * that a compiler that typechecks enums can flag a float/int tag mismatch during compile.)
  288.  *
  289.  * These variables are required by all drawing engines:
  290.  *        kQATag_ZFunction            (Int)    One of kQAZFunction_xxx
  291.  *        kQATag_ColorBG_a            (Float)    Background color alpha
  292.  *        kQATag_ColorBG_r            (Float)    Background color red
  293.  *        kQATag_ColorBG_g            (Float)    Background color green
  294.  *        kQATag_ColorBG_b            (Float)    Background color blue
  295.  *        kQATag_Width                (Float)    Line and point width (pixels)
  296.  *        kQATag_ZMinOffset            (Float)    Min offset to Z to guarantee visibility (Read only!)
  297.  *        kQATag_ZMinScale            (Float)    Min scale to Z to guarantee visibility (Read only!)
  298.  *
  299.  * These variables are used for optional features:
  300.  *        kQATag_Antialias            (Int)    One of kQAAntiAlias_xxx
  301.  *        kQATag_Blend                (Int)    One of kQABlend_xxx
  302.  *        kQATag_PerspectiveZ            (Int)    One of kQAPerspectiveZ_xxx
  303.  *        kQATag_TextureFilter        (Int)    One of kQATextureFilter_xxx
  304.  *        kQATag_TextureOp            (Int)    Mask of kQATextureOp_xxx
  305.  *        kQATag_Texture                (Int)    Pointer to current TQATexture
  306.  *        kQATag_CSGTag                (Int)    One of kQACSGTag_xxx
  307.  *        kQATag_CSGEquation            (Int)    32 bit CSG truth table
  308.  *
  309.  * These variables are used for OpenGL™ support:
  310.  *        kQATagGL_DrawBuffer            (Int)    Mask of kQAGL_DrawBuffer_xxx
  311.  *        kQATagGL_TextureWrapU        (Int)    kQAGL_Clamp or kQAGL_Repeat
  312.  *        kQATagGL_TextureWrapV        (Int)    kQAGL_Clamp or kQAGL_Repeat
  313.  *        kQATagGL_TextureMagFilter    (Int)    kQAGL_Nearest or kQAGL_Linear
  314.  *        kQATagGL_TextureMinFilter    (Int)    kQAGL_Nearest, etc.
  315.  *        kQATagGL_ScissorXMin        (Int)    Minimum X value for scissor rectangle
  316.  *        kQATagGL_ScissorYMin        (Int)    Minimum Y value for scissor rectangle
  317.  *        kQATagGL_ScissorXMax        (Int)    Maximum X value for scissor rectangle
  318.  *        kQATagGL_ScissorYMax        (Int)    Maximum Y value for scissor rectangle
  319.  *        kQATagGL_BlendSrc            (Int)    Source blending operation
  320.  *        kQATagGL_BlendDst            (Int)    Destination blending operation
  321.  *        kQATagGL_LinePattern        (Int)    Line rasterization pattern
  322.  *        kQATagGL_AreaPattern0        (Int)    First of 32 area pattern registers
  323.  *        kQATagGL_AreaPattern31        (Int)    Last of 32 area pattern registers
  324.  *        kQATagGL_DepthBG            (Float)    Background Z
  325.  *        kQATagGL_TextureBorder_a    (Float)    Texture border color alpha
  326.  *        kQATagGL_TextureBorder_r    (Float)    Texture border color red
  327.  *        kQATagGL_TextureBorder_g    (Float)    Texture border color green
  328.  *        kQATagGL_TextureBorder_b    (Float)    Texture border color blue
  329.  *
  330.  * Tags >= kQATag_EngineSpecific_Minimum may be assigned by the vendor for use as
  331.  * engine-specific variables. NOTE: These should be used only in exceptional circumstances,
  332.  * as functions performed by these variables won't be generally accessible. All other tag
  333.  * values are reserved.
  334.  *
  335.  *        kQATag_EngineSpecific_Minimum    Minimum tag value for drawing-engine specific variables
  336.  */
  337.  
  338. typedef enum TQATagInt
  339. {
  340.     kQATag_ZFunction                = 0,
  341.     kQATag_Antialias                = 8,
  342.     kQATag_Blend                    = 9,
  343.     kQATag_PerspectiveZ                = 10,
  344.     kQATag_TextureFilter            = 11,
  345.     kQATag_TextureOp                = 12,
  346.     kQATag_CSGTag                    = 14,
  347.     kQATag_CSGEquation                = 15,
  348.     kQATagGL_DrawBuffer                = 100,
  349.     kQATagGL_TextureWrapU            = 101,
  350.     kQATagGL_TextureWrapV            = 102,
  351.     kQATagGL_TextureMagFilter        = 103,
  352.     kQATagGL_TextureMinFilter        = 104,
  353.     kQATagGL_ScissorXMin            = 105,
  354.     kQATagGL_ScissorYMin            = 106,
  355.     kQATagGL_ScissorXMax            = 107,
  356.     kQATagGL_ScissorYMax            = 108,
  357.     kQATagGL_BlendSrc                = 109,
  358.     kQATagGL_BlendDst                = 110,
  359.     kQATagGL_LinePattern            = 111,
  360.     kQATagGL_AreaPattern0            = 117,
  361.         /* ...1-30 */
  362.     kQATagGL_AreaPattern31            = 148,
  363.     kQATag_EngineSpecific_Minimum    = 1000
  364. } TQATagInt;
  365.  
  366. typedef enum TQATagPtr
  367. {
  368.     kQATag_Texture                    = 13
  369. } TQATagPtr;
  370.  
  371. typedef enum TQATagFloat
  372. {
  373.     kQATag_ColorBG_a                = 1,
  374.     kQATag_ColorBG_r                = 2,
  375.     kQATag_ColorBG_g                = 3,
  376.     kQATag_ColorBG_b                = 4,
  377.     kQATag_Width                    = 5,
  378.     kQATag_ZMinOffset                = 6,
  379.     kQATag_ZMinScale                = 7,
  380.     kQATagGL_DepthBG                = 112,
  381.     kQATagGL_TextureBorder_a        = 113,
  382.     kQATagGL_TextureBorder_r        = 114,
  383.     kQATagGL_TextureBorder_g        = 115,
  384.     kQATagGL_TextureBorder_b        = 116
  385. } TQATagFloat;
  386.  
  387. /* kQATag_ZFunction */
  388. #define kQAZFunction_None            0    /* Z is neither tested nor written (same as no Z buffer) */
  389. #define kQAZFunction_LT                1    /* Znew < Zbuffer is visible */
  390. #define kQAZFunction_EQ                2    /* Znew == Zbuffer is visible */
  391. #define kQAZFunction_LE                3    /* Znew <= Zbuffer is visible */
  392. #define kQAZFunction_GT                4    /* Znew > Zbuffer is visible */
  393. #define kQAZFunction_NE                5    /* Znew != Zbuffer is visible */
  394. #define kQAZFunction_GE                6    /* Znew >= Zbuffer is visible */
  395. #define kQAZFunction_True            7    /* Znew is always visible */
  396.  
  397. /* kQATag_Width */
  398. #define kQAMaxWidth                    128.0
  399.  
  400. /* kQATag_Antialias */
  401. #define kQAAntiAlias_Off            0
  402. #define kQAAntiAlias_Fast            1
  403. #define kQAAntiAlias_Mid            2
  404. #define kQAAntiAlias_Best            3
  405.  
  406. /* kQATag_Blend */
  407. #define kQABlend_PreMultiply        0
  408. #define kQABlend_Interpolate        1
  409. #define kQABlend_OpenGL                2
  410.  
  411. /* kQATag_PerspectiveZ */
  412. #define kQAPerspectiveZ_Off            0    /* Use Z for hidden surface removal */
  413. #define kQAPerspectiveZ_On            1    /* Use InvW for hidden surface removal */
  414.  
  415. /* kQATag_TextureFilter */
  416. #define kQATextureFilter_Fast        0
  417. #define kQATextureFilter_Mid        1
  418. #define kQATextureFilter_Best        2
  419.  
  420. /* kQATag_TextureOp (mask of one or more) */
  421. #define kQATextureOp_None        0                /* Default texture mapping mode */
  422. #define kQATextureOp_Modulate    (1 << 0)        /* Modulate texture color with kd_r/g/b */
  423. #define kQATextureOp_Highlight    (1 << 1)        /* Add highlight value ks_r/g/b */
  424. #define kQATextureOp_Decal        (1 << 2)        /* When texture alpha == 0, use rgb instead */
  425. #define kQATextureOp_Shrink        (1 << 3)        /* This is a non-wrapping texture, so the
  426.                                                    range 0.0 <= uv <= 1.0 should not cause wrap */
  427.  
  428. /* kQATag_CSGTag */
  429. #define kQACSGTag_None            0xffffffffUL    /* Do not perform CSG */
  430. #define kQACSGTag_0                0                /* Submitted tris have CSG ID 0 */
  431. #define kQACSGTag_1                1                /* Submitted tris have CSG ID 1 */
  432. #define kQACSGTag_2                2                /* Submitted tris have CSG ID 2 */
  433. #define kQACSGTag_3                3                /* Submitted tris have CSG ID 3 */
  434. #define kQACSGTag_4                4                /* Submitted tris have CSG ID 4 */
  435.  
  436. /* kQATagGL_TextureWrapU/V */
  437. #define kQAGL_Repeat                0
  438. #define kQAGL_Clamp                    1
  439.  
  440. /* kQATagGL_BlendSrc */
  441. #define kQAGL_SourceBlend_XXX        0
  442.  
  443. /* kQATagGL_BlendDst */
  444. #define kQAGL_DestBlend_XXX            0
  445.  
  446. /* kQATagGL_DrawBuffer (mask of one or more) */
  447. #define kQAGL_DrawBuffer_None        0
  448. #define kQAGL_DrawBuffer_FrontLeft    (1<<0)
  449. #define kQAGL_DrawBuffer_FrontRight    (1<<1)
  450. #define kQAGL_DrawBuffer_BackLeft    (1<<2)
  451. #define kQAGL_DrawBuffer_BackRight    (1<<3)
  452. #define kQAGL_DrawBuffer_Front        (kQAGL_DrawBuffer_FrontLeft | kQAGL_DrawBuffer_FrontRight)
  453. #define kQAGL_DrawBuffer_Back        (kQAGL_DrawBuffer_BackLeft | kQAGL_DrawBuffer_BackRight)
  454.  
  455. /************************************************************************************************
  456.  *
  457.  * Constants used as function parameters.
  458.  *
  459.  ***********************************************************************************************/
  460.  
  461. /*
  462.  * TQAVertexMode is a parameter to QADrawVGouraud() and QADrawVTexture() that specifies how
  463.  * to interpret and draw the vertex array.
  464.  */
  465.  
  466. typedef enum TQAVertexMode
  467. {
  468.     kQAVertexMode_Point                = 0,        /* Draw nVertices points */
  469.     kQAVertexMode_Line                = 1,        /* Draw nVertices/2 line segments */
  470.     kQAVertexMode_Polyline            = 2,        /* Draw nVertices-1 connected line segments */
  471.     kQAVertexMode_Tri                = 3,        /* Draw nVertices/3 triangles */
  472.     kQAVertexMode_Strip                = 4,        /* Draw nVertices-2 triangles as a strip */
  473.     kQAVertexMode_Fan                = 5            /* Draw nVertices-2 triangles as a fan from v0 */
  474. } TQAVertexMode;
  475.  
  476. /*
  477.  * TQAGestaltSelector is a parameter to QAEngineGestalt(). It selects which gestalt
  478.  * parameter will be copied into 'response'.
  479.  */
  480.  
  481. typedef enum TQAGestaltSelector
  482. {
  483.     kQAGestalt_OptionalFeatures        = 0,        /* Mask of one or more kQAOptional_xxx */
  484.     kQAGestalt_FastFeatures            = 1,        /* Mask of one or more kQAFast_xxx */
  485.     kQAGestalt_VendorID                = 2,        /* Vendor ID */
  486.     kQAGestalt_EngineID                = 3,        /* Engine ID */
  487.     kQAGestalt_Revision                = 4,        /* Revision number of this engine */
  488.     kQAGestalt_ASCIINameLength        = 5,        /* strlen (asciiName) */
  489.     kQAGestalt_ASCIIName            = 6            /* Causes strcpy (response, asciiName) */
  490. } TQAGestaltSelector;
  491.  
  492. /*
  493.  * kQATriFlags_xxx are ORed together to generate the 'flags' parameter
  494.  * to QADrawTriGouraud() and QADrawTriTexture().
  495.  */
  496.  
  497. #define    kQATriFlags_None            0            /* No flags (triangle is front-facing or don't care) */
  498. #define kQATriFlags_Backfacing        (1 << 0)    /* Triangle is back-facing */
  499.  
  500. /*
  501.  * kQATexture_xxx are ORed together to generate the 'flags' parameter to QATextureNew().
  502.  */
  503.  
  504. #define    kQATexture_None                0            /* No flags */
  505. #define kQATexture_Lock                (1<<0)        /* Don't swap this texture out */
  506. #define kQATexture_Mipmap            (1<<1)        /* This texture is mipmapped */
  507.  
  508. /*
  509.  * kQABitmap_xxx are ORed together to generate the 'flags' parameter to QABitmapNew().
  510.  */
  511.  
  512. #define    kQABitmap_None                0            /* No flags */
  513. #define kQABitmap_Lock                (1<<1)        /* Don't swap this bitmap out */
  514.  
  515. /*
  516.  * kQAContext_xxx are ORed together to generate the 'flags' parameter for QADrawContextNew().
  517.  */
  518.  
  519. #define kQAContext_None                0            /* No flags */
  520. #define kQAContext_NoZBuffer        (1 << 0)    /* No hidden surface removal */
  521. #define kQAContext_DeepZ            (1 << 1)    /* Hidden surface precision >= 24 bits */
  522. #define kQAContext_DoubleBuffer        (1 << 2)    /* Double buffered window */
  523. #define kQAContext_Cache            (1 << 3)    /* This is a cache context */
  524.  
  525. /*
  526.  * kQAOptional_xxx are ORed together to generate the kQAGestalt_OptionalFeatures response
  527.  * from QAEngineGestalt().
  528.  */
  529.  
  530. #define kQAOptional_None            0            /* No optional features */
  531. #define kQAOptional_DeepZ            (1 << 0)    /* Hidden surface precision >= 24 bits */
  532. #define kQAOptional_Texture            (1 << 1)    /* Texture mapping */
  533. #define kQAOptional_TextureHQ        (1 << 2)    /* High quality texture (tri-linear mip or better) */
  534. #define kQAOptional_TextureColor    (1 << 3)    /* Full color modulation and highlight of textures */
  535. #define kQAOptional_Blend            (1 << 4)    /* Transparency blending of RGB */
  536. #define kQAOptional_BlendAlpha        (1 << 5)    /* Transparency blending includes alpha channel */
  537. #define kQAOptional_Antialias        (1 << 6)    /* Antialiased rendering */
  538. #define kQAOptional_ZSorted            (1 << 7)    /* Z sorted rendering (for transparency, etc.) */
  539. #define kQAOptional_PerspectiveZ    (1 << 8)    /* Hidden surface removal using InvW instead of Z */
  540. #define kQAOptional_OpenGL            (1 << 9)    /* Extended rasterization features for OpenGL™ */
  541. #define kQAOptional_NoClear            (1 << 10)    /* This drawing engine doesn't clear before drawing */
  542. #define kQAOptional_CSG                (1 << 11)    /* kQATag_CSGxxx are implemented */
  543. #define kQAOptional_BoundToDevice    (1 << 12)    /* This engine is tightly bound to GDevice */
  544.  
  545. /*
  546.  * kQAFast_xxx are ORed together to generate the kQAGestalt_FastFeatures response
  547.  * from QAEngineGestalt().
  548.  */
  549.  
  550. #define kQAFast_None                0            /* No accelerated features */
  551. #define kQAFast_Line                (1 << 0)    /* Line drawing */
  552. #define kQAFast_Gouraud                (1 << 1)    /* Gouraud shaded triangles */
  553. #define kQAFast_Texture                (1 << 2)    /* Texture mapped triangles */
  554. #define kQAFast_TextureHQ            (1 << 3)    /* High quality texture (tri-linear mip or better) */
  555. #define kQAFast_Blend                (1 << 4)    /* Transparency blending */
  556. #define kQAFast_Antialiasing        (1 << 5)    /* Antialiased rendering */
  557. #define kQAFast_ZSorted                (1 << 6)    /* Z sorted rendering of non-opaque objects */
  558.  
  559. /************************************************************************************************
  560.  *
  561.  * Macro definitions for the drawing engine methods included in TQADrawContext. These
  562.  * macros are the recommended means of accessing the engine's draw methods, e.g:
  563.  *
  564.  *        TQADrawContext    *drawContext;
  565.  *        TQAVTexture        vertices[3];
  566.  *
  567.  *        drawContext = QADrawContextNew (rect, gdevice, engine, kQAContext_ZBuffer);
  568.  *        ...
  569.  *        QASetInt (drawContext, kQATag_ZFunction, kQAZFunction_LT);
  570.  *        QADrawTriGouraud (drawContext, &vertices[0], &vertices[1], &vertices[2], kQATriFlags_None);
  571.  *
  572.  * Note that QARenderStart(), QARenderEnd(), QAFlush() and QASync() have real function
  573.  * definitions instead of macros. This is because these functions can afford the extra
  574.  * per-call overhead of a function layer (which makes application code a little smaller),
  575.  * and to allow a cleaner implementation of handling NULL parameters to QARenderStart().
  576.  *
  577.  ***********************************************************************************************/
  578.  
  579. #define QASetFloat(drawContext,tag,newValue) \
  580.         (drawContext)->setFloat (drawContext,tag,newValue)
  581.  
  582. #define QASetInt(drawContext,tag,newValue) \
  583.         (drawContext)->setInt (drawContext,tag,newValue)
  584.  
  585. #define QASetPtr(drawContext,tag,newValue) \
  586.         (drawContext)->setPtr (drawContext,tag,newValue)
  587.  
  588. #define QAGetFloat(drawContext,tag) \
  589.         (drawContext)->getFloat (drawContext,tag)
  590.  
  591. #define QAGetInt(drawContext,tag) \
  592.         (drawContext)->getInt (drawContext,tag)
  593.  
  594. #define QAGetPtr(drawContext,tag) \
  595.         (drawContext)->getPtr (drawContext,tag)
  596.  
  597. #define QADrawPoint(drawContext,v) \
  598.         (drawContext)->drawPoint (drawContext,v)
  599.  
  600. #define QADrawLine(drawContext,v0,v1) \
  601.         (drawContext)->drawLine (drawContext,v0,v1)
  602.  
  603. #define QADrawTriGouraud(drawContext,v0,v1,v2,flags) \
  604.         (drawContext)->drawTriGouraud (drawContext,v0,v1,v2,flags)
  605.  
  606. #define QADrawTriTexture(drawContext,v0,v1,v2,flags) \
  607.         (drawContext)->drawTriTexture (drawContext,v0,v1,v2,flags)
  608.  
  609. #define QADrawVGouraud(drawContext,nVertices,vertexMode,vertices,flags) \
  610.         (drawContext)->drawVGouraud (drawContext,nVertices,vertexMode,vertices,flags)
  611.  
  612. #define QADrawVTexture(drawContext,nVertices,vertexMode,vertices,flags) \
  613.         (drawContext)->drawVTexture (drawContext,nVertices,vertexMode,vertices,flags)
  614.  
  615. #define QADrawBitmap(drawContext,v,bitmap) \
  616.         (drawContext)->drawBitmap (drawContext,v,bitmap)
  617.  
  618. #define QARenderStart(drawContext,dirtyRect,initialContext) \
  619.         (drawContext)->renderStart (drawContext,dirtyRect,initialContext)
  620.  
  621. #define QARenderEnd(drawContext,modifiedRect) \
  622.         (drawContext)->renderEnd (drawContext,modifiedRect)
  623.  
  624. #define QARenderAbort(drawContext) \
  625.         (drawContext)->renderAbort (drawContext)
  626.  
  627. #define QAFlush(drawContext) \
  628.         (drawContext)->flush (drawContext)
  629.  
  630. #define QASync(drawContext) \
  631.         (drawContext)->sync (drawContext)
  632.  
  633. /************************************************************************************************
  634.  *
  635.  * Typedefs of draw method functions provided by the drawing engine. One function pointer
  636.  * for each of these function types in stored in the TQADrawContext public data structure.
  637.  *
  638.  * These functions should be accessed through the QA<function>(context,...) macros,
  639.  * defined above.
  640.  *
  641.  ***********************************************************************************************/
  642.  
  643. typedef void (*TQASetFloat) (
  644.     TQADrawContext            *drawContext,        /* Draw context */
  645.     TQATagFloat                tag,                /* Tag of variable to set */
  646.     float                    newValue);            /* New value for variable */
  647.  
  648. typedef void (*TQASetInt) (
  649.     TQADrawContext            *drawContext,        /* Draw context */
  650.     TQATagInt                tag,                /* Tag of variable to set */
  651.     unsigned long            newValue);            /* New value for variable */
  652.  
  653. typedef void (*TQASetPtr) (
  654.     TQADrawContext            *drawContext,        /* Draw context */
  655.     TQATagPtr                tag,                /* Tag of variable to set */
  656.     const void                *newValue);            /* New value for variable */
  657.  
  658. typedef float (*TQAGetFloat) (
  659.     const TQADrawContext    *drawContext,        /* Draw context */
  660.     TQATagFloat                tag);                /* Tag of variable to get */
  661.  
  662. typedef unsigned long (*TQAGetInt) (
  663.     const TQADrawContext    *drawContext,        /* Draw context */
  664.     TQATagInt                tag);                /* Tag of variable to get */
  665.  
  666. typedef void *(*TQAGetPtr) (
  667.     const TQADrawContext    *drawContext,        /* Draw context */
  668.     TQATagPtr                tag);                /* Tag of variable to get */
  669.  
  670. typedef void (*TQADrawPoint) (
  671.     const TQADrawContext    *drawContext,        /* Draw context */
  672.     const TQAVGouraud        *v);                /* Vertex */
  673.  
  674. typedef void (*TQADrawLine) (
  675.     const TQADrawContext    *drawContext,        /* Draw context */
  676.     const TQAVGouraud         *v0,                /* Vertex 0 */
  677.     const TQAVGouraud         *v1);                /* Vertex 1 */
  678.  
  679. typedef void (*TQADrawTriGouraud) (
  680.     const TQADrawContext    *drawContext,        /* Draw context */
  681.     const TQAVGouraud         *v0,                /* Vertex 0 */
  682.     const TQAVGouraud         *v1,                /* Vertex 1 */
  683.     const TQAVGouraud         *v2,                /* Vertex 2 */
  684.     unsigned long            flags);                /* Mask of kQATriFlags_xxx flags */
  685.  
  686. typedef void (*TQADrawTriTexture) (
  687.     const TQADrawContext    *drawContext,        /* Draw context */
  688.     const TQAVTexture         *v0,                /* Vertex 0 */
  689.     const TQAVTexture         *v1,                /* Vertex 1 */
  690.     const TQAVTexture         *v2,                /* Vertex 2 */
  691.     unsigned long            flags);                /* Mask of kQATriFlags_xxx flags */
  692.  
  693. typedef void (*TQADrawVGouraud) (
  694.     const TQADrawContext    *drawContext,        /* Draw context */
  695.     unsigned long            nVertices,            /* Number of vertices */
  696.     TQAVertexMode            vertexMode,            /* One of kQAVertexMode_xxx enumerated values */
  697.     const TQAVGouraud         vertices[],            /* Array of vertices */
  698.     const unsigned long        flags[]);            /* Array of per-triangle flags (or NULL) */
  699.  
  700. typedef void (*TQADrawVTexture) (
  701.     const TQADrawContext    *drawContext,        /* Draw context */
  702.     unsigned long            nVertices,            /* Number of vertices */
  703.     TQAVertexMode            vertexMode,            /* One of kQAVertexMode_xxx enumerated values */
  704.     const TQAVTexture         vertices[],            /* Array of vertices */
  705.     const unsigned long        flags[]);            /* Array of per-triangle flags (or NULL) */
  706.  
  707. typedef void (*TQADrawBitmap) (
  708.     const TQADrawContext    *drawContext,        /* Draw context */
  709.     const TQAVGouraud         *v,                    /* xyz, and (if a 1 bit/pixel bitmap) argb */
  710.     TQABitmap                *bitmap);            /* Previously allocated by QABitmapNew() */
  711.  
  712. typedef void (*TQARenderStart) (
  713.     const TQADrawContext    *drawContext,        /* Draw context */
  714.     const TQARect            *dirtyRect,            /* Minimum area to clear; NULL means whole buffer */
  715.     const TQADrawContext    *initialContext);    /* Initial background image (or NULL) */
  716.  
  717. typedef TQAError (*TQARenderEnd) (
  718.     const TQADrawContext    *drawContext,        /* Draw context */
  719.     const TQARect            *modifiedRect);        /* Minimum area to swap; NULL means whole buffer */
  720.  
  721. typedef TQAError (*TQARenderAbort) (
  722.     const TQADrawContext    *drawContext);        /* Draw context */
  723.  
  724. typedef TQAError (*TQAFlush) (
  725.     const TQADrawContext    *drawContext);        /* Draw context */
  726.  
  727. typedef TQAError (*TQASync) (
  728.     const TQADrawContext    *drawContext);        /* Draw context */
  729.  
  730. /************************************************************************************************
  731.  *
  732.  * Public TQADrawContext structure. This contains function pointers for the chosen
  733.  * drawing engine.
  734.  *
  735.  ***********************************************************************************************/
  736.  
  737. /*
  738.  * TQAVersion sets the TQADrawContext 'version' field. It is set by
  739.  * the manager to indicate the version of the TQADrawContext structure.
  740.  */
  741.  
  742. typedef enum TQAVersion
  743. {
  744.     kQAVersion_Prerelease        = 0,
  745.     kQAVersion_1_0                = 1
  746. } TQAVersion;
  747.  
  748. struct TQADrawContext
  749. {
  750.     TQADrawPrivate        *drawPrivate;        /* Engine's private data for this context */
  751.     const TQAVersion    version;            /* Version number */
  752.     TQASetFloat            setFloat;            /* Method: Set a float state variable */
  753.     TQASetInt            setInt;                /* Method: Set an unsigned long state variable */
  754.     TQASetPtr            setPtr;                /* Method: Set an unsigned long state variable */
  755.     TQAGetFloat            getFloat;            /* Method: Get a float state variable */
  756.     TQAGetInt            getInt;                /* Method: Get an unsigned long state variable */
  757.     TQAGetPtr            getPtr;                /* Method: Get an pointer state variable */
  758.     TQADrawPoint        drawPoint;            /* Method: Draw a point */
  759.     TQADrawLine            drawLine;            /* Method: Draw a line */
  760.     TQADrawTriGouraud    drawTriGouraud;        /* Method: Draw a Gouraud shaded triangle */
  761.     TQADrawTriTexture    drawTriTexture;        /* Method: Draw a texture mapped triangle */
  762.     TQADrawVGouraud        drawVGouraud;        /* Method: Draw Gouraud vertices */
  763.     TQADrawVTexture        drawVTexture;        /* Method: Draw texture vertices */
  764.     TQADrawBitmap        drawBitmap;            /* Method: Draw a bitmap */
  765.     TQARenderStart        renderStart;        /* Method: Initialize for rendering */
  766.     TQARenderEnd        renderEnd;            /* Method: Complete rendering and display */
  767.     TQARenderAbort        renderAbort;        /* Method: Abort any outstanding rendering (blocking) */
  768.     TQAFlush            flush;                /* Method: Start render of any queued commands (non-blocking) */
  769.     TQASync                sync;                /* Method: Wait for completion of all rendering (blocking) */
  770. };
  771.  
  772. /************************************************************************************************
  773.  *
  774.  * Acceleration manager function prototypes.
  775.  *
  776.  ***********************************************************************************************/
  777.  
  778. TQAError QADrawContextNew (
  779.     const TQADevice    *device,                /* Target device */
  780.     const TQARect    *rect,                    /* Target rectangle (device coordinates) */
  781.     const TQAClip    *clip,                    /* 2D clip region */
  782.     const TQAEngine    *engine,                /* Drawing engine to use */
  783.     unsigned long    flags,                    /* Mask of kQAContext_xxx */
  784.     TQADrawContext    **newDrawContext);        /* (Out) Newly created TQADrawContext */
  785.  
  786. void QADrawContextDelete (
  787.     TQADrawContext    *drawContext);            /* Context to delete */
  788.  
  789. TQAError QATextureNew (
  790.     const TQAEngine        *engine,            /* Drawing engine to use */
  791.     unsigned long        flags,                /* Mask of kQATexture_xxx flags */
  792.     TQAImagePixelType    pixelType,            /* Depth, color space, etc. */
  793.     const TQAImage        images[],            /* Image(s) for texture */
  794.     TQATexture            **newTexture);        /* (Out) Newly created TQATexture, or NULL on error */ 
  795.  
  796. TQAError QATextureDetach (
  797.     const TQAEngine        *engine,            /* Drawing engine to use */
  798.     TQATexture            *texture);            /* Previously allocated by QATextureNew() */
  799.  
  800. void QATextureDelete (
  801.     const TQAEngine        *engine,            /* Drawing engine to use */
  802.     TQATexture            *texture);            /* Previously allocated by QATextureNew() */
  803.  
  804. TQAError QABitmapNew (
  805.     const TQAEngine        *engine,            /* Drawing engine to use */
  806.     unsigned long        flags,                /* Mask of kQABitmap_xxx flags */
  807.     TQAImagePixelType    pixelType,            /* Depth, color space, etc. */
  808.     const TQAImage        *image,                /* Image */
  809.     TQABitmap            **newBitmap);        /* (Out) Newly created TQABitmap, or NULL on error */ 
  810.  
  811. TQAError QABitmapDetach (
  812.     const TQAEngine        *engine,            /* Drawing engine to use */
  813.     TQABitmap            *bitmap);            /* Previously allocated by QABitmapNew() */
  814.  
  815. void QABitmapDelete (
  816.     const TQAEngine        *engine,            /* Drawing engine to use */
  817.     TQABitmap            *bitmap);            /* Previously allocated by QABitmapNew() */
  818.  
  819. TQAEngine *QADeviceGetFirstEngine (
  820.     const TQADevice    *device);                /* Target device */
  821.  
  822. TQAEngine *QADeviceGetNextEngine (
  823.     const TQADevice    *device,                /* Target device */
  824.     const TQAEngine    *currentEngine);        /* Engine after 'currentEngine' is returned */
  825.  
  826. TQAError QAEngineCheckDevice (
  827.     const TQAEngine    *engine,                /* Engine to check on 'device' */
  828.     const TQADevice    *device);                /* Target device */
  829.  
  830. TQAError QAEngineGestalt (
  831.     const TQAEngine        *engine,            /* Engine being queried */
  832.     TQAGestaltSelector    selector,            /* Gestalt parameter being requested */
  833.     void                *response);            /* Buffer that receives response */
  834.  
  835. TQAError QAEngineEnable (
  836.     long            vendorID,                /* Vendor ID of engine to enable */
  837.     long            engineID);                /* Engine ID of engine to enable */
  838.  
  839. TQAError QAEngineDisable (
  840.     long            vendorID,                /* Vendor ID of engine to disable */
  841.     long            engineID);                /* Engine ID of engine to disable */
  842.  
  843. #ifdef __cplusplus
  844. }
  845. #endif
  846.  
  847. #endif /* _Drive3D_h */
  848.